package com.soft.javase.day11.copy;

import java.io.*;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/5/9
 */
public class FileCopy {
    public static void copyFile(String srcPath, String destPath) {
        try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcPath));
             BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destPath))) {

            byte[] buffer = new byte[8192];
            int len;
            while ((len = bis.read(buffer)) != -1) {
                bos.write(buffer, 0, len);
            }
            System.out.println("文件拷贝完成: " + destPath);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        String srcFile = "source.txt";
        String destFile = "destination.txt";
        copyFile(srcFile, destFile);
    }
}



